package cn.fly.Util;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.List;

import org.springframework.beans.factory.annotation.Value;
/**
 * @author mifei
 * @create 2018年04月19日
 **/
public class AnnotationUtil {

    public static void showMethods(List<Class<?>> clsList){
        if (clsList != null && clsList.size() > 0) {
            for (Class<?> cls : clsList) {
                //获取类中的所有的方法
                Method[] methods = cls.getDeclaredMethods();
                if (methods != null && methods.length > 0) {
                    for (Method method : methods) {
                        Value peopleAnnotion = (Value) method.getAnnotation(Value.class);
                        if (peopleAnnotion != null) {
                            //可以做权限验证
                            System.out.println(cls.getName());
                        }
                    }
                }
            }
        }
    }

    public static void showField(List<Class<?>> clsList){
        if (clsList != null && clsList.size() > 0) {
            for (Class<?> clz : clsList) {
                Field[] fields = clz.getDeclaredFields();
                for(Field field : fields){
                    boolean fieldHasAnno = field.isAnnotationPresent(Value.class);
                    if(fieldHasAnno){
                        Value fieldAnno = field.getAnnotation(Value.class);
                        //输出注解属性
                        System.out.println("有此注解的类"+clz.getName()+" 字段名:"+field.getName());
                    }
                }
            }
        }
    }
}
